import axios from 'axios'

export var service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
});
const err = error => {
  if (error.response) {
    let data = error.responese.data;
    let status = error.responese.status;
    console.log('----服务器异常响应----', error);
    switch (status) {}
  }
};
//请求拦截
service.interceptors.request.use(
  config => {

    return config;
  },
  error => {
    return Promise.reject(error);
  }
)
//响应拦截
service.interceptors.response.use(
  response => {
    if (response.request.responseType === 'blob') {
      return response;
    }
    const res = response.data
    // console.log(res);
    if (res.success == false) {
      globalThis.ELEMENT.Message.error(res.message || 'Error')
      return Promise.reject(new Error(res.message || 'Error'))

    } else {
      return res
    }
  },
  error => {

    globalThis.ELEMENT.Message.error(error || 'Has Error')

    return Promise.reject(error);
  }
);

